<?php
	require_once 'base.dao.php';
	require_once 'users_vao.php';
	
	class User_manager extends Base{
		
		public function __construct($conn){
			parent::__construct($conn);		
		}
		
		public function Login($name_user,$password) {
			$sql = sprintf("select * from USERS where name_user = '%s' and password = '%s'",
						    mysql_real_escape_string($name_user),
						    mysql_real_escape_string($password));
			
			$result = mysql_query($sql,$this->conn);
			
			if(!$result || mysql_num_rows($result) <= 0){
				throw new Exception('User/Password invalid.');
			}
			
			if($row = mysql_fetch_assoc($result)){
				extract($row);
				$user = new User($ID_USER,
								 $NAME_USER,
								 $PASSWORD,
								 $EMAIL_USER,
								 $REAL_NAME,
								 $LAST_LOGIN);
				return $user;
			}
		}
		
	}
?>